<template>
	<view class="container">
		<view class="container">
			<view class="user-section">
				<image class="bg" src="../../static/images/user-bg.png"></image>
				<!-- <view class="user-info-box" @click="navTo('/apiMember/memberinfo/main')"> -->
				<view class="user-info-box">
					<view class="portrait-box">
						<image class="portrait" :src="avator"></image>
					</view>
					<view class="info-box">
						<text class="username">{{userInfo.name || '请登录'}}</text>
					</view>
				</view>

				<view class="vip-card-box">
					<!-- <image class="card-bg" src="../../static/images/vip-card-bg.png" ></image> -->
					<view class="b-btn" v-if="statuslv === 'formallv'">
						查看信息
					</view>
					<view class="tit" style="color: #000000;">
						<div class="organizationName">{{userInfo.organizationName}}</div>
						<div class="organizationName">{{userInfo.customerTypeName}}</div>
						<div class="organizationName">{{userInfo.customerTypeChildName}}</div>
					</view>
				</view>
			</view>
			<view class="cover-container" :style="[{
				transform: coverTransform,
				transition: coverTransition
			}]"
			 @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
				<image class="arc" src="../../static/images/arc.png"></image>

				<view class="history-section" >
					<list-cell icon="icon-quanbudingdan" iconColor="#e07472" title="全部订单" border="" @eventClick="navTo('/apiMember/orderlist/main?status=0')"></list-cell>
				</view>
				<view class="history-section" v-if="(userInfo.permiss & 1) == 1" >
					<list-cell icon="icon-shenqing"  iconColor="#e07472" title="客户审批" border="" @eventClick="navTo('/apiMember/approve/main')"></list-cell>
				</view>
				<view class="history-section" v-if="(userInfo.permiss & 2) == 2"  >
					<list-cell icon="icon-baobiao2" iconColor="#e07472" title="报表统计" border="" @eventClick="navTo('/apiMember/orderReport/main')"></list-cell>
				</view>
				<view
				  class="history-section">
				<list-cell icon="icon-shezhi_" iconColor="#e07472" title="修改密码" border="" @eventClick="navTo('/apiPam/securitypwd/main')"></list-cell>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {
		toLogin,
		getStorageUserInfo,
		getStorageMemberId,
		get
	} from "@/server/api.js";
	import {
		myHelpTopicApi,
		memberInfoApi,
		GetPromoteApi
	} from "@/server/config.js";
	import listCell from "@/components/mix-list/mix-list-cell.vue";
	import Jfooter from "@/components/footer/footer.vue";
	import share from "@/common/share.js";

	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		async onShow() {
			let openId = uni.getStorageSync('openid');
			if (openId) {
				await get('/erp/openid/find', {openid:openId}).then(function(res) {
					if (!res.data.records[0]) {
						uni.navigateTo({
							url: "/apiPam/logincommon/main"
						});
					}
				})
			}
			if (!toLogin()) {
				return false;
			}
			this.userInfo = getStorageUserInfo();
			this.avator = "../../static/images/missing-face.png"//this.userInfo.avatarUrl; 
		},
		components: {
			listCell
		},
		data() {
			return {
				coverTransform: "translateY(0px)",
				coverTransition: "0s",
				moving: false,
				avator: "../../static/images/missing-face.png",
				allcheck: false,
				Listids: [],
				historyGoods: [],
				point: 0,
				modalName: null,
				couponNum: 0,
				advance: 0.0,
				userInfo: {},
				statuslv: "registerlv",
				rank_name: "", // 会员等级名称
				waitPayNum: 8, // 待付款数量
				waitRecNum: 3, // 待收货数量
				url: "" ,//分享链接
				
			};
		},
		onLoad() {},
		
		computed: {
			// ...mapState(['hasLogin','userInfo'])
		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
		  const index = e.index;
		  if (index === 0) {
		    this.navTo("/apiMember/set/main");
		  } else if (index === 1) {
		    // #ifdef APP-PLUS
		    const pages = getCurrentPages();
		    const page = pages[pages.length - 1];
		    const currentWebview = page.$getAppWebview();
		    currentWebview.hideTitleNViewButtonRedDot({
		      index
		    });
		    // #endif
		    uni.switchTab({
		      url: "/pages/topic/main"
		    });
		  }
		},
		// #endif
		methods: {
			async getData() {
				const data = await GetPromoteApi({});
				this.url = data.data.url;
				var code_url = data.data.code_url;
			},

			gotoLogin() {
				if (!this.userInfo.avatarUrl) {
					toLogin();
				}
			},
			goodsDetail(id) {
				console.log(id);
				uni.navigateTo({
					url: "/apiShop/goods/main?id=" + id
				});
			},
			getCacheGoodsList() {
				let historyGoods = uni.getStorageSync("historyGoods");
				this.historyGoods = historyGoods;
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (toLogin()) {
					uni.navigateTo({
						url
					});
				}
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target;
			},
			hideModal(e) {
				this.modalName = null;
			},
			go() {
				uni.makePhoneCall({
					// 手机号
					phoneNumber: this.kefu_tel,
					// 成功回调
					success: res => {
						console.log("调用成功!");
					},
					// 失败回调
					fail: res => {
						console.log("调用失败!");
					}
				});
			},
			kefu() {
				//#ifdef APP-PLUS
				// uni.showModal({
				//   title: "客服QQ",
				//   content: this.qq.toString(),
				//   confirmText: "打开QQ",
				//   success: function(res) {
				//     if (res.confirm) {
				//       plus.runtime.openURL(
				//         "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=" +
				//           this.qq +
				//           "&card_type=person&source=sharecard",
				//         function(res) {
				//           // console.log(res);
				//         }
				//       );
				//     } else if (res.cancel) {
				//       console.log("用户点击取消");
				//     }
				//   }
				// });
				//#endif
			},
			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = "transform .1s linear";
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = "transform 0.3s cubic-bezier(.21,1.93,.53,.64)";
				this.coverTransform = "translateY(0px)";
			}
		}
	};
</script>
<style lang='scss' scoped>
	@import "./style";
</style>
